#! /bin/sh

#/*
# *  This file is part of RTBM, Real-Time Bandwidth Monitor.
# *
# *  RTBM, Real-Time Bandwidth Monitor is free software: you can redistribute it and/or modify
# *  it under the terms of the GNU General Public License as published by
# *  the Free Software Foundation, either version 3 of the License, or
# *  (at your option) any later version.
# *
# *  RTBM, Real-Time Bandwidth Monitor is distributed in the hope that it will be useful,
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# *  GNU General Public License for more details.
# *
# *  You should have received a copy of the GNU General Public License
# *  along with RTBM, Real-Time Bandwidth Monitor.  If not, see <http://www.gnu.org/licenses/>.
# */

# Copyright (c) 2010 Nicolas Velasquez
# All rights reserved.
#
# Author: Nicolas Velasquez, 2010
#
# /etc/init.d/rtbm
#   and its symbolic link

### BEGIN INIT INFO
# Provides:          RTBM
# Required-Start:    $network
# Required-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: RTBM, a realtime bandwidth monitor that exposes statistics to the web
# Description:       RTBM is a network bandwidth monitor
#	service.  We want it to be active in runlevels 3
#	and 5, as these are the runlevels with the network
#	available.
### END INIT INFO

PID_FILE="/var/run/rtbm.pid"

# Check for missing binaries
RTBM_BIN=/usr/sbin/rtbm.py
test -x $RTBM_BIN || { echo "$RTBM_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

. /lib/lsb/init-functions

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"


case "$1" in
  start)
        log_daemon_msg "Starting Real Time Bandwidth Monitor server" "rtbm"
        if start-stop-daemon --start --oknodo --pidfile $PID_FILE --exec $RTBM_BIN -- --pid-file $PID_FILE; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;
  stop)
        log_daemon_msg "Stopping Real Time Bandwidth Monitor server" "rtbm"
        if start-stop-daemon --stop --oknodo --pidfile $PID_FILE; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;
  *)
        log_action_msg "Usage: /etc/init.d/rtbm {start|stop}"
        exit 1
esac

exit 0

